<?
include("session.php");

//date("Y-m-d H:i:s",strtotime("-12 Hours"))
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../webkit/utils/jquery.js"></script>
<script type="text/javascript" src="../webkit/grid/import.js"></script>
<script type="text/javascript" src="../webkit/dialog/import.js"></script>
<script type="text/javascript" src="../webkit/datepicker/WdatePicker.js"></script>
<script type="text/javascript" src="./common.js"></script>
<link type="text/css" rel="stylesheet" href="page.css"/>
</head>
<body>


<table width=100% height=100% cellspacing=0 cellpadding=0>
	<tr bgcolor="#eeeeee">
	<form name=f>
	<td height=30>&nbsp;
	任务：<select id="task_id"><option value=''>-请选择-</option></select>　
	结果：<select id="call_result"><option value=''>-请选择-</option><option value='1'>成功</option><option value='2'>失败</option></select>　
	状态：<select id="call_status"><option value=''>-请选择-</option><option value='0'>待呼</option><option value='2'>已呼</option><option value='-1'>已取消</option><option value='1'>队列中</option></select>　
	按键：<select id="user_select_key"><option value=''>-请选择-</option><?for($i=0; $i<10; $i++) {echo "<option value=$i>$i</option>";}?></select>　
	呼叫时间：<input type="text" id="date_start" name="date_start" onClick="WdatePicker({readOnly:true, skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="15" value=""> - <input type="text" id="date_end" name="date_end" onClick="WdatePicker({readOnly:true, skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="15" value="">　
	呼叫号码：<input type=text id='telephone' size=10>　
	<input type="button" value="查询" onclick="search()">　
	<?if($_SESSION['user_name'] == "admin") {?> [<a href='api_log_list.php'>接口日志</a>]<?}?>
	</td>
	</tr>
	<tr>
	<td>
		<table id="flex1" style="display:none"></table>
	</td>
	</form>
	</tr>
</table>
<iframe name=free height=1 width=0 frameborder=0></iframe>

<script type="text/javascript">
	var h = parent.document.body.clientHeight-(115+82);
	if(h < 0) h = 'auto'
	$("#flex1").flexigrid({
		url: 'call_query.php?action=list',
		dataType: 'json',
		colModel : [
			{display: 'ID', name : 'a', width : 40, sortable : false, align: 'center'},
			{display: '任务名称', name : 'task_name', width : 120, sortable : false, align: 'center'},
			{display: '外显号码', name : 'callout_number', width : 80, sortable : false, align: 'center'},
			{display: '呼叫号码', name : 'telephone', width : 90, sortable : false, align: 'center'},
			{display: '呼叫结果', name : 'call_result', width : 60, sortable : false, align: 'center'},
			{display: '呼叫时间', name : 'call_time', width : 120, sortable : false, align: 'center'},
			{display: '失败原因', name : 'fail_desc', width : 50, sortable : false, align: 'center'},
			{display: '接通时长', name : 'listen_time_long', width : 50, sortable : false, align: 'center'},
			{display: '用户按键', name : 'user_select_key', width : 50, sortable : false, align: 'center'},
			{display: '记录状态', name : 'call_status', width : 50, sortable : false, align: 'center'},
			{display: '导入时间', name : 'post_time', width : 120, sortable : false, align: 'center'},
			{display: '操作', name : 'op_link', width :80, sortable : false, align: 'center'},
			{display: '用户名称', name : 'user_name', width : 60, sortable : false, align: 'center'},
			{display: '附注信息', name : 'a', width : 180, sortable : false, align: 'center'}
		],
		buttons : [
			<?if($_SESSION['user_flag'] == "admin") {?>
			{name: '删除', bclass: 'del', onpress : del},
			<?}?>
			{name: '导出结果', bclass: 'other', onpress : export_excel},
			{name: '时段外呼统计', bclass: 'other', onpress : day_time_report}
			/*{name: '失败重呼', bclass: 'add', onpress : recall_fail},
			{name: '取消所有待呼', bclass: 'del', onpress : cancel_all_call}*/
		],
		async : true,
		usepager: true,
		title: '结果查询',
		useRp: true,
		rp: 15,
		showTableToggleBtn: false,
		width: 'auto',
		height: h,
		resizable : false,
		singleSelect : true
	});

	var f = document.f;
	function export_excel() { 
		if(f.task_id && f.task_id.value=='') {
			alert("请选择指定任务进行导出操作！");
			return false;
		}
		var url = "call_query.php?action=export_to_excel&task_id="+ $("#task_id").val();
        if($("#call_result").val()!="") {
            url += "&call_result="+ $("#call_result").val();
        }    
		if($("#user_select_key").val()!="") {
            url += "&user_select_key="+ $("#user_select_key").val();
        } 
        if($("#call_status").val()!="") {
            url += "&call_status="+ $("#call_status").val();
        }
	    if($("#date_start").val()!="" && $("#date_end").val()!="") {
            url += "&date_range="+ $("#date_start").val() +"_"+ $("#date_end").val();
        }    
		if(confirm('确认要导出当前所有记录吗？')) {
			window.free.location = url;
		}
	}

	function recall_fail() { alert('此功能暂未开放！'); }
    function cancel_all_call() { alert('此功能暂未开放！'); }

	function day_time_report() {
		var id = $("#flex1").getSelectedRowId();
		if(isNaN(id) || id<1) {
			id = ""
		}
		dlg = new Dialog({ title: '时段外呼统计', resizable:false, maximizable:false}).href("day_time_report.php?task_id="+id);
		dlg.show().setSize(800, 400).center();
	}


    function re_call(id) {
		if(confirm('确定要重新呼叫此号码吗？')) {
			$.get("call_query.php?action=re_call&id="+id, function(data) {
				if(data == "ok") {
					alert("操作成功！");
					refreshGrid();
				} else {
					alert(data);
				}
			});
		}
	}

    function cancel_call(id) {
		if(confirm('确定要取消此号码的呼叫吗？')) {
			$.get("call_query.php?action=cancel_call&id="+id, function(data) {
				if(data == "ok") {
					alert("操作成功！");
					refreshGrid();
				} else {
					alert(data);
				}
			});
		}
	}

	<?
	$del_url = "call_query.php?action=del&id=";
	require("grid_common_js.php");
	?>

	function search() { 
		var url = "call_query.php?action=list"; 
        if($("#date_start").val()!="" && $("#date_end").val()!="") {
            url += "&date_range="+ $("#date_start").val() +"_"+ $("#date_end").val();
        }      
        if($("#call_result").val()!="") {
            url += "&call_result="+ $("#call_result").val();
        }    
		if(f.task_id && $("#task_id").val()!="") {
            url += "&task_id="+ $("#task_id").val();
        } 
		if($("#user_select_key").val()!="") {
            url += "&user_select_key="+ $("#user_select_key").val();
        } 
        if($("#telephone").val()!="") {
            url += "&telephone="+ $("#telephone").val();
        }   
        if($("#call_status").val()!="") {
            url += "&call_status="+ $("#call_status").val();
        }
        if(f.task_name && $("#task_name").val()!="") {
            url += "&task_name="+ encodeURI($("#task_name").val());
        }     
		//window.open(url)
		$('#flex1').flexOptions({'url': url}).flexReload(); 
	}


	<?
	//if($_SESSION['user_flag'] == "user") { // 普通用户显示下拉列表
	?>
	$(function() {
		$.get("task_query.php?action=get_select_options", function(data) {
			var arr = data.split("$");
			for(var i=0; i<arr.length; i++){
				var kv = arr[i].split(',');
				f.task_id.options[i+1] = new Option(kv[1], kv[0]);
			}
		});
	});
	<?//}?>

</script>
</body>
</html>
